<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>遮盖层</title>
    <style>
        .btn {
            width: 100px;
            height: 50px;
            background-color: black;
            border-radius: 10px;
            color: #fff;
            font-size: 20px;
        }
        .btn:hover {
            cursor: pointer;
        }
        .del:hover {
            cursor: pointer;
        }
        .mask {
            position: fixed;
            top: 0;
            left: 0; 
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.5);
            display: flex;
            justify-content: center;
            align-items: center;
        }
       .hint {
            width: 200px;
            height: 100px;
            background-color: #fff; 
            border-radius: 10px;
            display: flex;
            justify-content: center;
            align-items: center;
        }
       .hidden {
            display: none;
        }
        .del {
            margin-left: 10px;
            height: 12px;
            width: 12px;
        }
    </style>
</head>
<body>
    <button class="btn">删除</button>
    <div class="mask hidden">
        <div class="hint">确认删除吗
            <span class="del">×</span>
        </div>
    </div>
    <script>
        let btnEle = document.querySelector('.btn');
        let maskEle = document.querySelector('.mask');
        let delEle = document.querySelector('.del');
        btnEle.addEventListener('click',function(){
            maskEle.classList.remove('hidden') 
        })
        delEle.addEventListener('click',function(){
            maskEle.classList.add('hidden') 
        })
        maskEle.addEventListener('click',function(){
            maskEle.classList.add('hidden')
        })
    </script>    
</body>
</html>